package afcp.alumni.model.db;

import java.io.Serializable;

import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import afcp.alumni.model.base.DatastoreEntity;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

//@Entity
@PersistenceCapable
public class Role implements DatastoreEntity, Serializable {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
//	@Id
	@PrimaryKey
	@Persistent
	// (valueStrategy = IdGeneratorStrategy.IDENTITY) // To allow automatic
	// generation when saving to datastore
	private Key key;
	@Persistent
	private String id;
	@Persistent
	private String label;
	@Persistent
	private boolean deletable = true;
	
	public Role() {
	}
	
	/**
	 * Creates a new {@link Role} which is a copy of the given one.
	 * @param role
	 */
	public Role(Role role) {
		id = role.getId();
		label = role.getLabel();
	}
	
//	public Role(String id, String label) {
//		this.key = KeyFactory.createKey(this.getClass().getSimpleName(), id);
//		this.label = label;
//	}

	public Key getKey() {
		return key;
	}
	public void setKeyWithAncestor(Key ancestorKey) {
		this.key = KeyFactory.createKey(ancestorKey, this.getClass().getSimpleName(), id);
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public boolean isDeletable() {
		return deletable;
	}
	public void setDeletable(boolean deletable) {
		this.deletable = deletable;
	}
	
	@Override
	public String toString() {
		return id;
	}

}
